﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EZCRS.HCMS.Data;
using EZCRS.HCMS.Entity;
using System.Data;
using System.Data.SqlClient;

namespace EZCRS.HCMS.SqlClient
{
    public class sql_AdmModule
    {
        private string ErrMsg = "";
        private string SqlStr = "";

        /// <summary>
        /// 错误信息
        /// </summary>
        public string ErrMsgs
        {
            get { return ErrMsg; }
        }

        #region 模块添加、修改
        /// <summary>
        /// 修改或添加模块
        /// </summary>
        /// <param name="ModName">模块名</param>
        /// <param name="ModUrl">模块url</param>
        /// <param name="ModParent">模块上级id</param>
        /// <param name="ModRank">模块排序</param>
        /// <param name="ModComment">模块描述</param>
        /// <param name="ModId">模块编号 空 为新增，其他为修改</param>
        /// <returns></returns>
        public bool Module_Add(string ModName, string ModUrl, string ModParent, string ModRank, string ModComment, string ModId)
        {
            SqlParameter[] pam = new SqlParameter[5];
            pam[0] = new SqlParameter("@modparent", ModParent);
            pam[1] = new SqlParameter("@modname", ModName);
            pam[2] = new SqlParameter("@modurl", ModUrl);
            pam[3] = new SqlParameter("@modrank", ModRank);
            pam[4] = new SqlParameter("@modcomment", ModComment);

            bool Rtn = true;
            if (ModId != "")
                SqlStr = "update hfg_module set modparent=@modparent,modname=@modname,modurl=@modurl,modrank=@modrank,modcomment=@modcomment where modid=" + ModId + "";
            else
                SqlStr = "insert into hfg_module(modparent,modname,modurl,modrank,modcomment) values(@modparent,@modname,@modurl,@modrank,@modcomment)";
            if (ExecSql.SqlExecNoquery(SqlStr, pam) > 0)
                return true;
            else
                return false;
        }
        #endregion

        #region 模块列表
        /// <summary>
        /// 返回模块列表
        /// </summary>
        /// <param name="ParentId">父级编号 0为顶级 ,空 为所有</param>
        /// <param name="ClassID">板块名称  1=酒店 2 =渠道 3 收益管理 4接口 5系统 0所有</param>
        /// <returns></returns>
        public DataTable Module_List(string ParentId, int classID)
        {
            if (classID > 0)
            {
                if (ParentId == "")
                    return ExecSql.GetDataSet("select * from hfg_module where classID=" + classID + "  order by modparent,modrank  ").Tables[0];
                else
                    return ExecSql.GetDataSet("select * from hfg_module where modparent=" + ParentId + "  and classID=" + classID + "  order by modrank ").Tables[0];
            }
            else 
            {
                if (ParentId == "")
                    return ExecSql.GetDataSet("select * from hfg_module   order by modparent,modrank  ").Tables[0];
                else
                    return ExecSql.GetDataSet("select * from hfg_module where modparent=" + ParentId + "   order by modrank ").Tables[0];
            }        
        }
        #endregion

        public DataRow Module_Item(string ModId)
        {
            try
            {
                return ExecSql.GetDataSet("select * from hfg_module where modid=" + ModId + "").Tables[0].Rows[0];
            }
            catch
            {
                return null;
            }
        }

        public bool Module_Del(string ModId)
        {
            if (ExecSql.SqlExecNoquery("delete from hfg_module where modid=" + ModId + ";delete from hfg_module where modparent=" + ModId + "") > 0)
                return true;
            else
                return false;
        }

        #region

        #endregion
    }
}
